package com.calefk.core {
	import flash.display.MovieClip;
	
	/**
     * Grupo de animaciones
     * @author Martin Melendez Blas
     */
    public class GAnimation extends EntitySimple {
        
        public var animations:Array;
        private var mAnimation:Animation;
        
        // retornar la animacion actual
        public function get animation():Animation { return mAnimation; }
        
        public function GAnimation(canvas:MovieClip, nameClip:String = null, px:Number = 0, py:Number = 0) {
            super(canvas, nameClip, px, py);
            animations = new Array();
			
        }
        /**
         * 
         * @param	idClip sera el id para la aniamcion tambien
         * @param	isLoop si se reproducirar indefinidamente
         * @return retorna la animacion
         */
        public function addAnimation(idClip:String , px:Number = 0 , py:Number = 0 , isLoop:Boolean = false):Animation {
            var animation:Animation = new Animation(mClip , idClip , px , py , isLoop);
            animations[idClip] = animation;
            return animation;
        }
        
        public function changeAnimation(idAnimation:String):void {
            // ocualtar todos
            for each (var a:Animation in animations) {
                a.visible(false);
            }
            // visualizar solo la animacion correspondiente
            mAnimation = animations[idAnimation];
            mAnimation.visible(true);
            mAnimation.start();
        }
        
        override public function update(dt:int):void {
            if (mAnimation) {
                mAnimation.update(dt);
            }
        }
        
        override public function clean():void {
            for (var key:String in animations) {
                var a:Animation = animations[key];
                a.clean();
                delete animations[key];
            }
            animations = null;
            mAnimation = null;
            super.clean();
        }
        
    }

}